package com.test03_类与对象;

import org.junit.Test;

/**
 * 类与对象
 */
public class YootkDemo_01 {

    @Test
    public void test1() {
        {
            Book book = new Book();
            book.getInfo();
        }
        {
            Book book = new Book();
            book.title = "沐言Java";
            book.author = "李兴华";
            book.price = 89.6;
            book.getInfo();
        }
    }

    @Test
    public void test2() {
        Book book = null;   // 声明对象
        book = new Book();  // 实例化对象
        book.getInfo();
        book.title = "沐言Java";
        book.author = "李兴华";
        book.price = 89.6;
        book.getInfo();
    }

    @Test
    public void test3() {
        Book bookA = new Book();
        bookA.title = "沐言Java";
        bookA.author = "李兴华";
        bookA.price = 89.6;
        Book bookB = bookA;
        bookB.author = "小李老师";
        bookB.price = 78.6;
        bookA.getInfo();
    }
}

/**
 * 图书类
 */
class Book {
    String title;   // 图书名称
    String author;  // 图书作者
    double price;   // 图书价格

    public void getInfo() {
        System.out.println("图书名称：" + title + "、图书作者：" + author + "、图书价格：" + price);
    }
}
